package com.ygq.Impl;

import DO.LogoDO;
import DTO.AddLogoDTO;
import com.ygq.LogoService;
import mapper.LogoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import result.Result;

import java.util.List;
import java.util.Objects;


@Service
public class LogoServiceImpl implements LogoService {


    @Autowired
    private LogoMapper logoMapper;

    // 判断有无重复
    public Integer getByIsrepeat(AddLogoDTO addLogoDTO) {
        List<LogoDO> logoDOS = logoMapper.logoBythree();
        for (LogoDO logoDO : logoDOS) {
            if (logoDO.getLogo().equals(addLogoDTO.getLogo())){
                return -1; // -1表示签到名称有重复
            }

            // 判断班级是否在3个小时以内发布过签到
            for (Integer aClass : addLogoDTO.getClasses()) {
                if (Objects.equals(aClass, logoDO.getClassId())){
                    return aClass;
                }
            }
        }
        return 0;
    }

    // 保存签到
    public void save(LogoDO logoDO) {
        logoMapper.save(logoDO);
    }

    @Override
    public LogoDO getListLogoByClassId(Integer classId) {
        return logoMapper.getByClassId(classId);
    }



    public List<LogoDO> getAll() {
        return logoMapper.logoBythree();
    }


    public LogoDO getById(Integer logoId) {
        return logoMapper.getById(logoId);
    }
}
